package com.eascs.web.o2o.web.reward.controller;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.eascs.app.dao.PageResult;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.common.util.UrlUtil;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.page.SelectDataOption;
import com.eascs.site.view.PaginationRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.web.context.RequestContext;
import com.eascs.web.o2o.web.reward.entity.ProvinceOverdueQueryForm;
import com.eascs.web.o2o.web.reward.service.ProvinceOverdueService;

@RestController
@RequestMapping("/provinceOverdueRest")
public class ProvinceOverdueRestController {

	private static Logger log = LoggerFactory.getLogger(ProvinceOverdueRestController.class);

	@Autowired
	ProvinceOverdueService provinceOverdueService;
	
  	
  	 //根据省区查询逾期报表
  	@RequestMapping("/provinceOverdueDetail")
  	public PaginationRestResult overdueReportDetail(ProvinceOverdueQueryForm entity) {
  		String o2ourl = "/provinceOverdueRest/provinceOverdueDetail";
  		Calendar c = Calendar.getInstance();
		c.add(Calendar.MONTH, -1);
		String date=new SimpleDateFormat("yyyy-MM").format(c.getTime());
		String month = entity.getMonth()==null?date:entity.getMonth();
		entity.setMonth(month);
  		if (entity != null) {
  			 String province = entity.getProvince() == null ? "" : entity.getProvince();
  			 String monthData = entity.getMonth() == null ? "" : entity.getMonth();
			 o2ourl = UrlUtil.appendUrl(o2ourl, "month", monthData);
			 o2ourl = UrlUtil.appendUrl(o2ourl, "province", province);
			 o2ourl = o2ourl + "&showPage=";
  		}else {
  			o2ourl = o2ourl + "?showPage=";
  		} 
  		entity.setPageSize(15);
  		PageResult<Object[]> pageResult = provinceOverdueService.getProvinceOverdueDetail(entity);
  		String titles[] = { "考核月份", "省区", "贷款单号","借款人姓名", "信贷经理工号", "信贷经理名称", "放款金额(万元)", "放款时间","到期时间","本年累计逾期本息(万元)","本年累计回款本息(万元)","本年累计到期本金(万元)"};
  		SelectDataOption[] selectDataOptions = { null, null,null,null, null, null, null, null, null, null,null, null};
  		PaginationInfo o2oPagingInfo = new PaginationInfo(pageResult, titles, UrlUtil.resetParam(RequestContext.getRequestUrlWithQueryString(), "showPage", ""));
  		//PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, UrlUtil.resetParam(RequestContext.getRequestUrlWithQueryString(), "showPage", ""));

  		o2oPagingInfo.setBuildPagingNavigation(true);
  		o2oPagingInfo.setFirstRenderColumnIndex(0);
  		o2oPagingInfo.setSelectDataOptions(selectDataOptions);
  		//o2oPagingInfo.setFormats(new Format[] { null, null, new DecimalFormat(",##0.00"), null, new DecimalFormat(",##0.00"), null,  new DecimalFormat(",##0.00"),null, new DecimalFormat(",##0.00"), null , new DecimalFormat(",##0.00"), null , new DecimalFormat(",##0.00")});
  		o2oPagingInfo.setRendTo("#o2o_result");
  		ViewContext.put("vo", entity);
  		return PaginationRestResult.buildPaginationRestResult(o2oPagingInfo);
  	}
	

}
